/*
 * transmission-remote-java remote control for transmission daemon
 *
 * Copyright (C) 2009  dvstar
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.dvstar.transmission.dialogs;

import net.sf.dvstar.transmission.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.swing.event.ChangeEvent;
import net.sf.dvstar.transmission.utils.ConfigStorage;
import net.sf.dvstar.transmission.protocol.ProtocolConstants;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.event.ChangeListener;
import net.sf.dvstar.transmission.utils.LocalSettiingsConstants;
import net.sf.dvstar.transmission.utils.Tools;
import org.jdesktop.application.Action;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ClientConfigDialog.java
 *
 * Created on 03.06.2009, 15:29:34
 */
/**
 *
 * @author dstarzhynskyi
 */
public class ClientConfigDialog extends javax.swing.JDialog implements ProtocolConstants, LocalSettiingsConstants {

    private List profileList = new ArrayList();
    TransmissionView parent;

    /** Creates new form ClientConfigDialog */
    public ClientConfigDialog(TransmissionView parent, boolean modal) {
        super(parent.getFrame(), modal);
        this.parent = parent;
        initComponents();

        cbDestination.removeAllItems();

        loadConfig();

        cbProfile.addActionListener(new ComboBoxProfileAction());
        lbColor_TR_STATUS_STOPPED.addMouseListener(new ColorMouseListener(this, lbColor_TR_STATUS_STOPPED, TR_STATUS_PAUSED));
        lbColor_TR_STATUS_CHECK_WAIT.addMouseListener(new ColorMouseListener(this, lbColor_TR_STATUS_CHECK_WAIT, TR_STATUS_CHECK_WAIT));
        lbColor_TR_STATUS_CHECK.addMouseListener(new ColorMouseListener(this, lbColor_TR_STATUS_CHECK, TR_STATUS_CHECK));
        lbColor_TR_STATUS_DOWNLOAD.addMouseListener(new ColorMouseListener(this, lbColor_TR_STATUS_DOWNLOAD, TR_STATUS_DOWNLOAD));
        lbColor_TR_STATUS_SEED.addMouseListener(new ColorMouseListener(this, lbColor_TR_STATUS_SEED, TR_STATUS_SEED));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel7 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tfConnHost = new javax.swing.JTextField();
        tfConnPort = new javax.swing.JTextField();
        tfConnRefresh = new javax.swing.JTextField();
        tfConnTryCount = new javax.swing.JTextField();
        chbConnUseSSL = new javax.swing.JCheckBox();
        chbConnAuto = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tfAuthLogin = new javax.swing.JTextField();
        pfAuthPasswd = new javax.swing.JPasswordField();
        jPanel10 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        tfProxyHost = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        tfProxyPort = new javax.swing.JTextField();
        chbProxyUse = new javax.swing.JCheckBox();
        jLabel9 = new javax.swing.JLabel();
        tfProxyLogin = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        chbProxyAuth = new javax.swing.JCheckBox();
        pfProxyPasswd = new javax.swing.JPasswordField();
        jPanel8 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        cbLocale = new javax.swing.JComboBox();
        jPanel9 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jPanel13 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        lbColor_TR_STATUS_DOWNLOAD = new javax.swing.JLabel();
        lbColor_TR_STATUS_CHECK = new javax.swing.JLabel();
        lbColor_TR_STATUS_CHECK_WAIT = new javax.swing.JLabel();
        lbColor_TR_STATUS_SEED = new javax.swing.JLabel();
        lbColor_TR_STATUS_STOPPED = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        cbDestination = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        cbProfile = new javax.swing.JComboBox();
        btAddProfile = new javax.swing.JButton();
        btDelProfile = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(420, 180));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(300, 230));
        jPanel3.setLayout(new java.awt.BorderLayout());

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(608, 230));

        jPanel7.setName("jPanel7"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(net.sf.dvstar.transmission.TransmissionApp.class).getContext().getResourceMap(ClientConfigDialog.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        tfConnHost.setName("tfConnHost"); // NOI18N

        tfConnPort.setName("tfConnPort"); // NOI18N

        tfConnRefresh.setName("tfConnRefresh"); // NOI18N

        tfConnTryCount.setName("tfConnTryCount"); // NOI18N

        chbConnUseSSL.setText(resourceMap.getString("chbConnUseSSL.text")); // NOI18N
        chbConnUseSSL.setName("chbConnUseSSL"); // NOI18N

        chbConnAuto.setText(resourceMap.getString("chbConnAuto.text")); // NOI18N
        chbConnAuto.setName("chbConnAuto"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        tfAuthLogin.setColumns(10);
        tfAuthLogin.setName("tfAuthLogin"); // NOI18N

        pfAuthPasswd.setColumns(10);
        pfAuthPasswd.setText(resourceMap.getString("pfAuthPasswd.text")); // NOI18N
        pfAuthPasswd.setName("pfAuthPasswd"); // NOI18N

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
                        .addGap(56, 56, 56))
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfConnRefresh)
                            .addComponent(tfConnPort, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chbConnAuto)
                            .addComponent(chbConnUseSSL)))
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(tfAuthLogin, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pfAuthPasswd, javax.swing.GroupLayout.Alignment.LEADING))
                    .addComponent(tfConnHost, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfConnTryCount, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(261, 261, 261))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfConnHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfConnPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chbConnAuto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfConnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chbConnUseSSL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfConnTryCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tfAuthLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(pfAuthPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(59, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel7.TabConstraints.tabTitle"), jPanel7); // NOI18N

        jPanel10.setName("jPanel10"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        tfProxyHost.setName("tfProxyHost"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        tfProxyPort.setName("tfProxyPort"); // NOI18N

        chbProxyUse.setSelected(true);
        chbProxyUse.setText(resourceMap.getString("chbProxyUse.text")); // NOI18N
        chbProxyUse.setName("chbProxyUse"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        tfProxyLogin.setEnabled(false);
        tfProxyLogin.setName("tfProxyLogin"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        chbProxyAuth.setText(resourceMap.getString("chbProxyAuth.text")); // NOI18N
        chbProxyAuth.setName("chbProxyAuth"); // NOI18N

        pfProxyPasswd.setText(resourceMap.getString("pfProxyPasswd.text")); // NOI18N
        pfProxyPasswd.setEnabled(false);
        pfProxyPasswd.setName("pfProxyPasswd"); // NOI18N

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfProxyHost, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(tfProxyPort, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(pfProxyPasswd, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tfProxyLogin, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(chbProxyAuth, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(chbProxyUse, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE))
                .addGap(199, 199, 199))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfProxyHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(8, 8, 8)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(chbProxyUse))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfProxyLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(pfProxyPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chbProxyAuth))
                .addContainerGap(114, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel10.TabConstraints.tabTitle"), jPanel10); // NOI18N

        jPanel8.setName("jPanel8"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        cbLocale.setName("cbLocale"); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbLocale, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(353, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(cbLocale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(195, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel8.TabConstraints.tabTitle"), jPanel8); // NOI18N

        jPanel9.setName("jPanel9"); // NOI18N

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 514, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 228, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel9.TabConstraints.tabTitle"), jPanel9); // NOI18N

        jPanel11.setName("jPanel11"); // NOI18N

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 514, Short.MAX_VALUE)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 228, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel11.TabConstraints.tabTitle"), jPanel11); // NOI18N

        jPanel12.setName("jPanel12"); // NOI18N
        jPanel12.setLayout(new java.awt.GridLayout(1, 2));

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel13.border.title"))); // NOI18N
        jPanel13.setName("jPanel13"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        lbColor_TR_STATUS_DOWNLOAD.setForeground(resourceMap.getColor("lbColor_TR_STATUS_DOWNLOAD.foreground")); // NOI18N
        lbColor_TR_STATUS_DOWNLOAD.setText(resourceMap.getString("lbColor_TR_STATUS_DOWNLOAD.text")); // NOI18N
        lbColor_TR_STATUS_DOWNLOAD.setName("lbColor_TR_STATUS_DOWNLOAD"); // NOI18N

        lbColor_TR_STATUS_CHECK.setForeground(resourceMap.getColor("lbColor_TR_STATUS_CHECK.foreground")); // NOI18N
        lbColor_TR_STATUS_CHECK.setText(resourceMap.getString("lbColor_TR_STATUS_CHECK.text")); // NOI18N
        lbColor_TR_STATUS_CHECK.setName("lbColor_TR_STATUS_CHECK"); // NOI18N

        lbColor_TR_STATUS_CHECK_WAIT.setForeground(resourceMap.getColor("lbColor_TR_STATUS_CHECK_WAIT.foreground")); // NOI18N
        lbColor_TR_STATUS_CHECK_WAIT.setText(resourceMap.getString("lbColor_TR_STATUS_CHECK_WAIT.text")); // NOI18N
        lbColor_TR_STATUS_CHECK_WAIT.setName("lbColor_TR_STATUS_CHECK_WAIT"); // NOI18N

        lbColor_TR_STATUS_SEED.setForeground(resourceMap.getColor("lbColor_TR_STATUS_SEED.foreground")); // NOI18N
        lbColor_TR_STATUS_SEED.setText(resourceMap.getString("lbColor_TR_STATUS_SEED.text")); // NOI18N
        lbColor_TR_STATUS_SEED.setName("lbColor_TR_STATUS_SEED"); // NOI18N

        lbColor_TR_STATUS_STOPPED.setForeground(resourceMap.getColor("lbColor_TR_STATUS_STOPPED.foreground")); // NOI18N
        lbColor_TR_STATUS_STOPPED.setText(resourceMap.getString("lbColor_TR_STATUS_STOPPED.text")); // NOI18N
        lbColor_TR_STATUS_STOPPED.setName("lbColor_TR_STATUS_STOPPED"); // NOI18N

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbColor_TR_STATUS_DOWNLOAD, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                    .addComponent(lbColor_TR_STATUS_SEED, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                    .addComponent(lbColor_TR_STATUS_STOPPED, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                    .addComponent(lbColor_TR_STATUS_CHECK, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                    .addComponent(lbColor_TR_STATUS_CHECK_WAIT, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(lbColor_TR_STATUS_DOWNLOAD))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(lbColor_TR_STATUS_CHECK))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(lbColor_TR_STATUS_CHECK_WAIT))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(lbColor_TR_STATUS_SEED))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(lbColor_TR_STATUS_STOPPED))
                .addContainerGap(108, Short.MAX_VALUE))
        );

        jPanel12.add(jPanel13);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel6.border.title"))); // NOI18N
        jPanel6.setName("jPanel6"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        cbDestination.setEditable(true);
        cbDestination.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbDestination.setName("cbDestination"); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbDestination, 0, 225, Short.MAX_VALUE)
                    .addComponent(jLabel17))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbDestination, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(160, Short.MAX_VALUE))
        );

        jPanel12.add(jPanel6);

        jTabbedPane1.addTab(resourceMap.getString("jPanel12.TabConstraints.tabTitle"), jPanel12); // NOI18N

        jPanel3.add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel3, java.awt.BorderLayout.CENTER);

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(120, 230));
        jPanel4.setLayout(new java.awt.GridLayout(2, 0));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel5.border.title"))); // NOI18N
        jPanel5.setMinimumSize(new java.awt.Dimension(120, 127));
        jPanel5.setName("jPanel5"); // NOI18N

        cbProfile.setEditable(true);
        cbProfile.setName("cbProfile"); // NOI18N

        btAddProfile.setIcon(resourceMap.getIcon("btAddProfile.icon")); // NOI18N
        btAddProfile.setName("btAddProfile"); // NOI18N
        btAddProfile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddProfileActionPerformed(evt);
            }
        });

        btDelProfile.setIcon(resourceMap.getIcon("btDelProfile.icon")); // NOI18N
        btDelProfile.setName("btDelProfile"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbProfile, 0, 88, Short.MAX_VALUE)
                    .addComponent(btAddProfile)
                    .addComponent(btDelProfile))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(cbProfile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btAddProfile)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btDelProfile)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel4.add(jPanel5);

        jPanel1.add(jPanel4, java.awt.BorderLayout.EAST);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(400, 42));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(net.sf.dvstar.transmission.TransmissionApp.class).getContext().getActionMap(ClientConfigDialog.class, this);
        jButton1.setAction(actionMap.get("saveConfig")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.setPreferredSize(new java.awt.Dimension(120, 23));

        jButton2.setAction(actionMap.get("saveConfigClose")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setPreferredSize(new java.awt.Dimension(120, 23));

        jButton3.setAction(actionMap.get("closeDialog")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.setPreferredSize(new java.awt.Dimension(120, 23));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(242, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btAddProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddProfileActionPerformed
        if (cbProfile.getSelectedItem() != null) {
            Object objRef = cbProfile.getSelectedItem();
            if (profileList != null && profileList.indexOf(objRef) < 0) {
                profileList.add(objRef);
                cbProfile.addItem(objRef);
            }
        }
    }//GEN-LAST:event_btAddProfileActionPerformed

    @Action
    public void saveConfigClose() {
        saveConfig();
        closeDialog();
    }

    @Action
    public void closeDialog() {
        this.dispose();
    }

    @Action
    public void saveConfig() {
        //     if(//)
        Properties prop = new Properties();
        String configPrefix = "";

        //ConfigStorage.setPropertiesPrefix(configPrefix);
        ConfigStorage configStorage = new ConfigStorage();
        // load from disk for update

        Object objRef = cbProfile.getSelectedItem();
        int selIndex = cbProfile.getSelectedIndex();

        if (objRef != null) {
            configPrefix = objRef.toString();
        }

        configStorage.propertiesManager(CONF_CLI_CURRENTPROFILE, prop, configPrefix, DIR_GET, false);
        configStorage.propertiesManager(CONF_CLI_PROFILES, prop, profileList, DIR_GET, false);
        configStorage.propertiesManager(CONF_CLI_LOCALE, prop, cbLocale, DIR_GET);


        if (configPrefix != null && configPrefix.length() > 0) {
            configStorage.setDefaultProfile(configPrefix);
        }

        configStorage.propertiesManager(CONF_CLI_HOST, prop, tfConnHost, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PORT, prop, tfConnPort, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_REFRESHRATE, prop, tfConnRefresh, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_RETRYLIMIT, prop, tfConnTryCount, DIR_GET);

        configStorage.propertiesManager(CONF_CLI_PROXYHOST, prop, tfProxyHost, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PROXYPORT, prop, tfProxyPort, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PROXYUSER, prop, tfProxyLogin, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PROXYPASS, prop, pfProxyPasswd, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PROXYENABLED, prop, chbProxyUse, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PROXYAUTH, prop, chbProxyAuth, DIR_GET);

        configStorage.propertiesManager(CONF_CLI_USER, prop, tfAuthLogin, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_PASS, prop, pfAuthPasswd, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_USESSL, prop, chbConnUseSSL, DIR_GET);
        configStorage.propertiesManager(CONF_CLI_AUTOCONNECT, prop, chbConnAuto, DIR_GET);

        configStorage.propertiesManager(CONF_CLI_COL_STATUS_CHECK_WAIT, prop, lbColor_TR_STATUS_CHECK_WAIT.getForeground(), DIR_GET);
        configStorage.propertiesManager(CONF_CLI_COL_STATUS_CHECK, prop, lbColor_TR_STATUS_CHECK.getForeground(), DIR_GET);
        configStorage.propertiesManager(CONF_CLI_COL_STATUS_DOWNLOAD, prop, lbColor_TR_STATUS_DOWNLOAD.getForeground(), DIR_GET);
        configStorage.propertiesManager(CONF_CLI_COL_STATUS_SEED, prop, lbColor_TR_STATUS_SEED.getForeground(), DIR_GET);
        configStorage.propertiesManager(CONF_CLI_COL_STATUS_STOPPED, prop, lbColor_TR_STATUS_STOPPED.getForeground(), DIR_GET);


        String dstDirs = "";
        if (cbDestination.getItemCount() > 0) {
            for (int i = 0; i < cbDestination.getItemCount(); i++) {
                String delim = ",";
                if (i == cbDestination.getItemCount() - 1) {
                    delim = "";

                }
                dstDirs += cbDestination.getItemAt(i) + delim;
            }
        }
        configStorage.setProperty(CONF_CLI_USED_DIRS, dstDirs);
        configStorage.propertiesManager(CONF_CLI_USED_DIRS, prop, dstDirs, DIR_GET, false);


        configStorage.saveConfig(prop);

    }

    private void updateProfile(String curProfile) {
        Properties prop;
        ConfigStorage configStorage = new ConfigStorage();
        configStorage.loadConfig();

        prop = configStorage.getStoredConfig();

        if (curProfile.length() > 0) {
            configStorage.setDefaultProfile(curProfile);
            cbProfile.setSelectedItem(curProfile);
        }

        configStorage.propertiesManager(CONF_CLI_HOST, prop, tfConnHost, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PORT, prop, tfConnPort, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_REFRESHRATE, prop, tfConnRefresh, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_RETRYLIMIT, prop, tfConnTryCount, DIR_SET);

        configStorage.propertiesManager(CONF_CLI_PROXYHOST, prop, tfProxyHost, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PROXYPORT, prop, tfProxyPort, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PROXYUSER, prop, tfProxyLogin, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PROXYPASS, prop, pfProxyPasswd, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PROXYENABLED, prop, chbProxyUse, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PROXYAUTH, prop, chbProxyAuth, DIR_SET);

        configStorage.propertiesManager(CONF_CLI_USER, prop, tfAuthLogin, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_PASS, prop, pfAuthPasswd, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_USESSL, prop, chbConnUseSSL, DIR_SET);
        configStorage.propertiesManager(CONF_CLI_AUTOCONNECT, prop, chbConnAuto, DIR_SET);

        Color col = null;
        col = configStorage.propertiesManager(CONF_CLI_COL_STATUS_CHECK_WAIT, prop, lbColor_TR_STATUS_CHECK_WAIT.getForeground(), DIR_SET);
        if (col != null) {
            lbColor_TR_STATUS_CHECK_WAIT.setForeground(col);
        }
        col = configStorage.propertiesManager(CONF_CLI_COL_STATUS_CHECK, prop, lbColor_TR_STATUS_CHECK.getForeground(), DIR_SET);
        if (col != null) {
            lbColor_TR_STATUS_CHECK.setForeground(col);
        }
        col = configStorage.propertiesManager(CONF_CLI_COL_STATUS_DOWNLOAD, prop, lbColor_TR_STATUS_DOWNLOAD.getForeground(), DIR_SET);
        if (col != null) {
            lbColor_TR_STATUS_DOWNLOAD.setForeground(col);
        }
        col = configStorage.propertiesManager(CONF_CLI_COL_STATUS_SEED, prop, lbColor_TR_STATUS_SEED.getForeground(), DIR_SET);
        if (col != null) {
            lbColor_TR_STATUS_SEED.setForeground(col);
        }
        col = configStorage.propertiesManager(CONF_CLI_COL_STATUS_STOPPED, prop, lbColor_TR_STATUS_STOPPED.getForeground(), DIR_SET);
        if (col != null) {
            lbColor_TR_STATUS_STOPPED.setForeground(col);
        }


        List<Locale> listLocales = Tools.getListOfAvailLanguages();

        for (int i = 0; i < listLocales.size(); i++) {
            String country = listLocales.get(i).getCountry().toUpperCase();
            if(country.length()>0) {
                country = "_" + country;
            }
            cbLocale.addItem(listLocales.get(i).getLanguage()+country ); //getDisplayLanguage(Locale.ENGLISH));
        }

        Locale defaultLocale = parent.getDefaultLocale();
        String country = defaultLocale.getCountry().length()>0?"_"+defaultLocale.getCountry().toUpperCase():"";
        String defaultLocaleString = defaultLocale.getLanguage()+country;
        //!!parent.tracePrint(true, "LOCALE "+defaultLocale + " "+defaultLocale.getDisplayCountry()+" " +defaultLocale.getCountry()+" "+defaultLocale.getDisplayLanguage());
        cbLocale.setSelectedItem(defaultLocaleString);

        //!!configStorage.propertiesManager(CONF_CLI_AUTOCONNECT, prop, chbConnAuto, DIR_SET);

        String dlist = configStorage.getProperty(CONF_CLI_USED_DIRS);
        if (dlist != null && dlist.length()>0) {

            StringTokenizer stoken = new StringTokenizer(dlist, ",");
            if (stoken.countTokens() > 0) {
                while (stoken.hasMoreElements()) {
                    //values.add(stoken.nextToken());
                    cbDestination.addItem(stoken.nextToken());
                }
            } else {
                //values.add(dlist);
                cbDestination.addItem(dlist);
            }
        }
        cbDestination.addActionListener(new MyActionListener());

    }

    @Action
    private void loadConfig() {
        Properties prop;
        ConfigStorage configStorage = new ConfigStorage();
        configStorage.loadConfig();
        prop = configStorage.getStoredConfig();
        String curProfile = "";

        //ConfigStorage.setPropertiesPrefix("");
        curProfile = configStorage.propertiesManager(CONF_CLI_CURRENTPROFILE, prop, curProfile, DIR_SET, false);
        profileList = configStorage.propertiesManager(CONF_CLI_PROFILES, prop, profileList, DIR_SET, false);

        if (profileList != null && profileList.size() > 0) {
            cbProfile.removeAllItems();
            for (int i = 0; i < profileList.size(); i++) {
                cbProfile.addItem(profileList.get(i));
            }
        }

        if (curProfile.length() > 0) {
            //ConfigStorage.setPropertiesPrefix(curProfile);
            cbProfile.setSelectedItem(curProfile);
        }
        updateProfile(curProfile);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddProfile;
    private javax.swing.JButton btDelProfile;
    private javax.swing.JComboBox cbDestination;
    private javax.swing.JComboBox cbLocale;
    private javax.swing.JComboBox cbProfile;
    private javax.swing.JCheckBox chbConnAuto;
    private javax.swing.JCheckBox chbConnUseSSL;
    private javax.swing.JCheckBox chbProxyAuth;
    private javax.swing.JCheckBox chbProxyUse;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lbColor_TR_STATUS_CHECK;
    private javax.swing.JLabel lbColor_TR_STATUS_CHECK_WAIT;
    private javax.swing.JLabel lbColor_TR_STATUS_DOWNLOAD;
    private javax.swing.JLabel lbColor_TR_STATUS_SEED;
    private javax.swing.JLabel lbColor_TR_STATUS_STOPPED;
    private javax.swing.JPasswordField pfAuthPasswd;
    private javax.swing.JPasswordField pfProxyPasswd;
    private javax.swing.JTextField tfAuthLogin;
    private javax.swing.JTextField tfConnHost;
    private javax.swing.JTextField tfConnPort;
    private javax.swing.JTextField tfConnRefresh;
    private javax.swing.JTextField tfConnTryCount;
    private javax.swing.JTextField tfProxyHost;
    private javax.swing.JTextField tfProxyLogin;
    private javax.swing.JTextField tfProxyPort;
    // End of variables declaration//GEN-END:variables

    public class ComboBoxProfileAction implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            String curProfile = cbProfile.getSelectedItem().toString();
            System.out.println("curProfile=" + curProfile);
            updateProfile(curProfile);
        }
    }

    class ColorMouseListener implements MouseListener, ChangeListener {

        private JColorChooser tcc;
        private final int status;
        private final JDialog parent;
        private Color currColor;
        private JComponent compon;

        public ColorMouseListener(JDialog parent, JComponent comp, int status) {
            this.status = status;
            this.parent = parent;
            this.compon = comp;
            currColor = compon.getForeground();
            tcc = new JColorChooser(currColor);
            tcc.getSelectionModel().addChangeListener(this);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            tcc.setVisible(true);
            currColor = tcc.showDialog(parent, "Foreground for ...", currColor);
            if (currColor != null) {
                compon.setForeground(currColor);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void stateChanged(ChangeEvent e) {
            currColor = tcc.getColor();
            lbColor_TR_STATUS_STOPPED.setForeground(currColor);
        }
    }


    class MyActionListener implements ActionListener, ItemListener {

        Object oldItem;
        private String dstDir;

        @Override
        public void actionPerformed(ActionEvent evt) {
            JComboBox cb = (JComboBox) evt.getSource();
            Object newItem = cb.getSelectedItem();

            dstDir = cb.getSelectedItem().toString();


            JComboBox anCombo = (JComboBox) evt.getSource();
            DefaultComboBoxModel comboModel = (DefaultComboBoxModel) anCombo.getModel();
            int index = comboModel.getIndexOf(anCombo.getSelectedItem());
            if (index == -1) {
                comboModel.addElement(anCombo.getSelectedItem());
            }//else already added

            /*
            System.out.println("+++++++"+newItem+"="+oldItem);

            boolean same = newItem.equals(oldItem);
            oldItem = newItem;


            if (!same) {
            if(((MyComboBoxModel) cb.getModel()).getValues().indexOf(newItem)<0){
            ((MyComboBoxModel) cb.getModel()).getValues().add(newItem);
            System.out.println("======="+cb.getItemCount());

            }
            }

            if ("comboBoxEdited".equals(evt.getActionCommand())) {
            // User has typed in a string; only possible with an editable combobox
            System.out.println("======="+evt);
            } else if ("comboBoxChanged".equals(evt.getActionCommand())) {
            }
             */
        }

        @Override
        public void itemStateChanged(ItemEvent e) {
        }
    }

}
